#!/usr/bin/env python
#  -*- coding: utf-8 -*-
__author__ = 'yinq'


def search(hostname):
    with open("haproxy.conf", 'r', encoding='utf-8') as f:
        for index, line in enumerate(f.readlines()):
            if hostname in line:
                if "backend" in line:
                    print(line, index)
                    exit()


def new_host():
    pass


def delete_host():
    pass


if __name__ == '__main__':
    while True:
        print("1.搜索\n2.新建\n3.删除\nq.退出")
        choice_num = input("please input number:")
        if choice_num.isdigit():
            choice_num = int(choice_num)
            if choice_num == 1:
                hostname = input("please input hostname:")
                search(hostname)
            elif choice_num == 2:
                pass
            elif choice_num == 3:
                pass

            else:
                print("\033[31;1mplease input current number!!\033[0m")

        elif choice_num == 'q':
            exit()
        else:
            print("\033[31;1mplease input current number!!\033[0m")
